home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / ida / aux / scanf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  1.0 KB  |  59 lines

  1. /*
  2. **  SCANF -- Program to scan & extract input lines.
  3. **  Copyright (c) 1987, 1988 Lennart Lovstrand
  4. **  CIS Dept, Univ of Linkoping, Sweden
  5. **
  6. **  Use it, abuse it, but don't sell it.
  7. **
  8. **  Very simple version 0.11 of Tue Aug 23 12:01:10 BST 1988
  9. */
  10.  
  11. #include "sendmail.h"
  12.  
  13. main(argc, argv)
  14.     int argc;
  15.     char **argv;
  16. {
  17.     char buf[BUFSIZ], val[BUFSIZ];
  18.     FILE *input;
  19.     bool ignore_case = FALSE;
  20.  
  21.     if (argc > 1 && strcmp(argv[1], "-i") == 0) {
  22.     ignore_case = TRUE;
  23.     argc--; argv++;
  24.     }
  25.  
  26.     if (argc < 2 || argc > 3) {
  27.     fprintf(stderr, "usage: scanf [-i] scanf_pattern [file]\n");
  28.     exit(1);
  29.     }
  30.  
  31.     if (ignore_case)
  32.     lowerit(argv[1]);
  33.  
  34.     if (argc == 2)
  35.     input = stdin;
  36.     else {
  37.     input = fopen(argv[2], "r");
  38.     if (input == NULL) {
  39.         perror(argv[2]);
  40.         exit(1);
  41.     }
  42.     }
  43.  
  44.     while (fgets(buf, sizeof(buf), input) != NULL) {
  45.     if (ignore_case)
  46.         lowerit(buf);
  47.     if (sscanf(buf, argv[1], val) == 1)
  48.         puts(val);
  49.     }
  50. }
  51.  
  52. lowerit(p)
  53.     register char *p;
  54. {
  55.     for (; *p != '\0'; p++)
  56.     if (isupper(*p))
  57.         *p = tolower(*p);
  58. }
  59.